#! /usr/bin/env python
# -*- coding: utf-8 -*-

"""
Модуль для реализации класса грида стереографической проекции
"""

from plane import Plane

class PlaneGrid():
    def __init__(self, incr=None, size=None):
        if incr==None:
            dip_incr = 90/size[1]
            dir_incr = 360/size[0]
        else:
            dip_incr = incr[1]
            dir_incr = incr[0]            
        self.dir_incr = dir_incr
        self.dip_incr = dip_incr

        # Создание пустого грида
        self.grid = [[0] * (90 / dip_incr) for i in xrange(0, 360, dir_incr)]
                

    def add(self, plane=None, item=None, val=1):
        if plane:
            dir = int(plane.dir)
            dip = int(plane.dip)
	    if dip == 90: dip = 89
        item = (dir/self.dir_incr, dip/self.dip_incr)
        self.grid[item[0]][item[1]] += val

    def set(self, plane=None, item=None, val=0):
        if plane:
            dir = int(plane.dir)
            dip = int(plane.dip)
        if dip == 90: dip = 89
        item = (dir/self.dir_incr, dip/self.dip_incr)
        self.grid[item[0]][item[1]] = val

    def get(self, plane=None, item=None):
        if plane:
            dir = plane.dir
            dip = plane.dip
	    if dip == 90: dip = 89
        item = (dir/self.dir_incr, dip/self.dip_incr)
        return self.grid[item[0]][item[1]]

    def returnGrid(self):
        return self.grid

def main():
    grid = PlaneGrid(incr=(10,10))
    print grid.returnGrid()
    grid.add(item=(0,0))
    print ''
    print grid.returnGrid()
    from plane import Plane
    a=Plane(40, 60)
    b=Plane(120, 12)
    grid.add(plane=a)
    grid.add(plane=b)
    print grid.get(plane=a)
    print grid.get(plane=b)
    print ''
    print grid.returnGrid()



if __name__=='__main__':
    main()
        
